/*
*******************************************************************
* Copyright (c) 2003-2020  TECHNOLOGY CO.,LTD.
* All Rights Coding Guideline for Programming Language C R00
Confidential Document - Reproduction, Disclosure and Circulation without authorization is prohibited
* Filename : Led.c
* Project : 06_Button_control_LED_light
* Description :
* Note(s) :
* Update Record:
* Version   Date          Modified by     Why & What is modified
* 00.00     YYYY.MM.DD    Á¢Ð¾Ç¶ÈëÊ½       Initial Version
*******************************************************************
*/
#include "Led.h"

static uint8_t led_init()
{
    //This section is generated by Cube
    return 0;
}

#if 0
static void led_on()
{
    HAL_GPIO_WritePin(Led_GPIO_Port,Led_Pin,GPIO_PIN_RESET);
}

static void led_off()
{
    HAL_GPIO_WritePin(Led_GPIO_Port,Led_Pin,GPIO_PIN_SET);
}
#endif

static void led_toggle()
{
    HAL_GPIO_TogglePin(Led_GPIO_Port,Led_Pin);
}

//Led task runnable
void led_task_runnable(void)
{
    static uint8_t task_state = 0;
    static uint32_t key_press_cnt = 0;
    static uint8_t cnt_state = 0;
    if(task_state == 0)
    {
        if(led_init() == 0)
        {
            task_state = 1;
        }
    }
    else
    {
        if(g_E_key_state == KEY_PRESSED)
        {
            cnt_state = 1;
        }
        else
        {
            cnt_state = 0;
        }

        if(cnt_state == 1)
        {
            key_press_cnt++;
        }
        else
        {
            if(key_press_cnt >= LED_FLIP_EVENT_FILTER_TIME)
            {
                led_toggle();
            }
            key_press_cnt = 0;
        }
    }
}
